using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Campus
{
    public class InformationOverlay
    {
        private SpriteFont m_lucidaConsole;
        #region All the Fields and their getters/setters
        /// <summary>
        /// Names and strings that represent info (level, special attributes, etc)
        /// </summary>
        private List<KeyValuePair<string, string>> m_information = new List<KeyValuePair<string,string>>();
        public List<KeyValuePair<string, string>> Information
        {
            get { return m_information; }
            set { m_information = value; }
        }

        /// <summary>
        /// Where it will be drawn (absolute coords. for upper left corner)
        /// </summary>
        private Vector2 m_location;
        public Vector2 Location
        {
            get { return m_location; }
            set { m_location = value; }
        }

        /// <summary>
        /// Color to tint the image or set opacity
        /// </summary>
        /// <summary>
        /// Color to tint the image or set opacity
        /// </summary>
        private Color m_imageColor = Color.White;
        public Color ImageColor
        {
            get { return m_imageColor; }
            set { m_imageColor = value; }
        }
        public byte ImageOpacity
        {
            get { return m_imageColor.A; }
            set { m_imageColor = new Color(m_imageColor.R, m_imageColor.G, m_imageColor.B, value); }
        }
        private SpriteFont m_spriteFont = null; 
        public SpriteFont Font
        {
            get { return m_spriteFont; }
            set { m_spriteFont = value; }
        }
        
        /// <summary>
        /// Color to tint the font or set opacity of font
        /// </summary>
        private Color m_fontColor = Color.White;
        public Color FontColor
        {
            get { return m_fontColor; }
            set { m_fontColor = value; }
        }
        public byte FontOpacity
        {
            get { return m_fontColor.A; }
            set { m_fontColor = new Color(m_fontColor.R, m_fontColor.G, m_fontColor.B, value); }
        }

        private bool m_isClicked = false;
        public bool IsClicked
        {
            get { return m_isClicked; }
            set { m_isClicked = value; }
        }

        /// <summary>
        /// x and y size of the info. overlay
        /// </summary>
        private Vector2 m_size;
        public Vector2 Size
        {
            get { return m_size; }
            set { m_size = value; }
        }

        /// <summary>
        /// Image to be drawn (as a background for the info. overlay)
        /// </summary>
        /// 
       
        private Texture2D m_image;
        public Texture2D Image
        {
            get { return m_image; }
            set { m_image = value; }
        }
        #endregion

        #region All the Constructors
        public InformationOverlay(Vector2 location, Vector2 size)
        {
            Location = location;
            Size = size;
        }
        public InformationOverlay(Texture2D image, Vector2 location, Color color, Vector2 size)
        {
            Image = image;
            Location = location;
            ImageColor = color;
            Size = size;
        }
        
        public InformationOverlay(Vector2 location, Vector2 size, List<KeyValuePair<string, string>> information)
        {
            Location = location;
            Size = size;
            Information = information;
        }
        public InformationOverlay(Texture2D image, Vector2 location, Color color, Vector2 size, List<KeyValuePair<string, string>> information)
        {
            Image = image;
            Location = location;
            ImageColor = color;
            Size = size;
            Information = information;
        }
        public InformationOverlay(Vector2 location, Vector2 size, SpriteFont font, string name, string text) {
            Size = size;
            Location = location;
            Font = font;
            bool temp = AddInformation(name, text);
            //m_information = null;
        }
        public InformationOverlay(Vector2 location, Vector2 size, Texture2D image, Color color)
        {
            Image = image;
            Location = location;
            ImageColor = color;
            Size = size;
           // m_information = null;
        } 
        #endregion

        #region All other Functions
        /// <summary>
        /// Draws the information overlay
        /// </summary>
        public void Draw(SpriteBatch spriteBatch)
        {
            
            
            spriteBatch.Begin();
            if (m_image != null)
            {
                spriteBatch.Draw(m_image, new Rectangle((int)Location.X, (int)Location.Y, (int)Size.X, (int)Size.Y), ImageColor);
            }
            if (Information != null && m_spriteFont !=null)
            {
                for (int i = 0; i < Information.Count; i++)
                {
                    spriteBatch.DrawString(m_spriteFont,Information[i].Value,
                                           Location, FontColor);
                }
            }
            spriteBatch.End();
            // Draw the options.
        }
        /// <summary>
        /// Modifies a piece of information that is stored in the information overlay
        /// </summary>
        /// <param name="name">The name of the piece of information to modify</param>
        /// <param name="information">The new value for that piece of information</param>
        /// <returns>true if successful, false if the piece of information was not in this information overlay</returns>
        public bool ModifyInformation(String name, string information)
        {
            if (Information == null)
            {
                return false;
            }
            for (int i = 0; i < Information.Count; i++)
            {
                if (Information[i].Key == name)
                {
                    Information[i] = new KeyValuePair<string, string>(name, information);
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// Adds a piece of information to the information overlay
        /// </summary>
        /// <param name="name">The name for the new piece of information</param>
        /// <param name="information">The new piece of information</param>
        /// <returns>true if successful, false if the given name already exists</returns>
        public bool AddInformation(string name, string information)
        {
            KeyValuePair<string, string> info;
            if (Information == null)
            {
                info = new KeyValuePair<string, string>(name, information);
                Information.Add(info);
                return true;
            }
            for (int i = 0; i < Information.Count; i++)
            {
                if (Information[i].Key == name)
                {
                    return false;
                }
            }
            info = new KeyValuePair<string, string>(name, information);
            Information.Add(info);
            return true;
        }

        /// <summary>
        /// Removes the piece of information of the given name from the information overlay
        /// </summary>
        /// <param name="name">The name of the piece of information to remove</param>
        public void RemoveInformation(string name)
        {
            if (Information == null)
            {
                return;
            }
            for (int i = 0; i < Information.Count; i++)
            {
                if (Information[i].Key == name)
                {
                    Information.RemoveAt(i);
                    return;
                }
            }

        }
        #endregion
    }
}